package com.chinamobile.iot.kafka;

import com.alibaba.fastjson.JSON;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by szl on 2017/8/9.
 */
@Component
public class KafkaDataEventProducer {
    private static final Logger logger = LoggerFactory.getLogger(KafkaDataEventProducer.class);

    @Autowired
    private KafkaProducerClient kafkaProducerClient;

    public KafkaDataEventProducer() {
    }

    public void sendEvent(String deviceId, String topic, Object msg) {
        ProducerRecord<String, String> record = new ProducerRecord<String, String>(topic, deviceId, JSON.toJSONString(msg));
        kafkaProducerClient.send(record);
    }
}
